package com.hangxin.configurations.controller;

import com.hangxin.common.annotation.Anonymous;
import com.hangxin.common.core.controller.BaseController;
import com.hangxin.common.core.domain.AjaxResult;
import com.hangxin.configurations.domain.DocCmpStyleCfg;
import com.hangxin.configurations.domain.DocKeyStatCfg;
import com.hangxin.configurations.domain.vo.DocSettingVo;
import com.hangxin.configurations.service.IDocCmpStyleCfgService;
import com.hangxin.configurations.service.IDocKeyStatCfgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 文档关键信息统计设置表 Controller
 *
 * @author ZX
 */
@RestController
@RequestMapping("/configurations/custom")
public class DocKeyStatCfgController extends BaseController {

    @Autowired
    private IDocCmpStyleCfgService docCmpStyleCfgService;
    @Autowired
    private IDocKeyStatCfgService docKeyStatCfgService;

    /**
     * 获取设置配置
     */
    @GetMapping("/setting")
    public AjaxResult setting() {
        DocKeyStatCfg docKeyStatCfg = docKeyStatCfgService.getById(1);
        DocCmpStyleCfg docCmpStyleCfg = docCmpStyleCfgService.getById(1);
        return AjaxResult.success(new DocSettingVo(docCmpStyleCfg, docKeyStatCfg));
    }

    /**
     * 保存当前设置
     */
    @PutMapping("/confirm")
    public AjaxResult confirm(@RequestBody DocSettingVo docSettingVo) {
        DocCmpStyleCfg docCmpStyleCfg = docSettingVo.getDocCmpStyleCfg();
        docCmpStyleCfg.setUpdateTime(LocalDateTime.now());
        DocKeyStatCfg docKeyStatCfg = docSettingVo.getDocKeyStatCfg();
        docKeyStatCfg.setUpdateTime(LocalDateTime.now());
        docCmpStyleCfgService.updateById(docCmpStyleCfg);
        docKeyStatCfgService.updateById(docKeyStatCfg);
        return toAjax(1);
    }
}